/*
 * =====================================================================================
 *
 *       Filename:  serial.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2018年04月16日 14时20分13秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  jianxi sun (jianxi), ycsunjane@gmail.com
 *   Organization:  
 *
 * =====================================================================================
 */
#ifndef __SERIAL_H__
#define __SERIAL_H__
#include <ev.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

#include "buffer.h"

typedef struct serial_ctx {
	ev_io io;
	ev_timer watcher;
	ev_timer htwatcher;
	void *serial;
} serial_ctx_t;

typedef struct serial {
	int fd;
	buffer_t *rxbuf;
	buffer_t *txbuf;
	serial_ctx_t *recv_ctx;
	serial_ctx_t *send_ctx;
} serial_t;

serial_t *create_serial();
void close_and_free_serial(EV_P_ serial_t *serial);
#endif /* __SERIAL_H__ */
